import { useInitDataSingleton } from './shared';
import { BasFormConfigApi, BasFormConfigOutput, BasFormConfigInput } from '/@/api/bas/BasFormConfig';

// 表单配置, 按需加载, 不导出
const { list, initList: initBasFormConfigList } = useInitDataSingleton<BasFormConfigOutput>(BasFormConfigApi.all);

// 表单配置
export async function getFormConfig(tag: string, formId: string) {
	await initBasFormConfigList();
	return list.value.find((x) => x.tag == tag && x.id == formId) ?? ({} as BasFormConfigOutput);
}

// 保存表单配置
export async function saveFormConfig(input: BasFormConfigInput) {
	await BasFormConfigApi.save(input);
	list.value = [];
	await initBasFormConfigList();
}
